package com.sky.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
public class RedisConfiguration {
    @Bean
    public RedisTemplate<Object,Object> redisTemplate(RedisConnectionFactory connectionFactory) {

        RedisTemplate<Object,Object> redisTemplate = new RedisTemplate<>();
        //设置key的编码格式
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        //设置value的编码格式
        redisTemplate.setValueSerializer(new StringRedisSerializer());
        //设置hash编码格式
        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
        redisTemplate.setHashValueSerializer(new StringRedisSerializer());
        //设置redis数据源
        redisTemplate.setConnectionFactory(connectionFactory);
        return redisTemplate;
    }
}
